package com.meusconcursos;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Toast;

import com.meusconcursos.dto.PlanoEstudo;

public class PlanoEstudoListActivity extends ListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setTitle(R.string.titulo_lista_planoestudo);
		setContentView(R.layout.list_planoestudo);

		ArrayAdapter<PlanoEstudo> adapter = new ArrayAdapter<PlanoEstudo>(this,
				android.R.layout.simple_list_item_1,
				MeusConcursosActivity.dbHelper.getPlanosEstudo());
		setListAdapter(adapter);

		getListView().setOnItemClickListener(
				new AdapterView.OnItemClickListener() {

					@Override
					public void onItemClick(AdapterView<?> parent, View child,
							int position, long id) {

						PlanoEstudo planoEstudo = (PlanoEstudo) parent
								.getItemAtPosition(position);

						Intent intent = new Intent(getBaseContext(),
								ProvaListActivity.class);

						intent.putExtra("id_formacao", planoEstudo.getIdFormacao());
						intent.putExtra("id_planoestudo", planoEstudo.getId());

						startActivity(intent);
					}
				});

		getListView().setOnItemLongClickListener(
				new AdapterView.OnItemLongClickListener() {

					@Override
					public boolean onItemLongClick(AdapterView<?> parentView,
							View arg1, int position, long arg3) {

						PlanoEstudo planoEstudo = (PlanoEstudo) parentView
								.getItemAtPosition(position);

						Toast.makeText(
								getBaseContext(),
								planoEstudo.getNomeCargo() + " [Previsto: "
										+ planoEstudo.getTotalPrevisto()
										+ "h Realizado: "
										+ planoEstudo.getTotalRealizado()
										+ "h]", Toast.LENGTH_LONG).show();

						return false;
					}
				});

	}

}